
var sendReq = createAjaxObj();
var receiveReq = createAjaxObj();
var msg;
var lastShowTime;
var count = 0;

function startThread() {
	try{
		getChatText();
	}catch(e){
		
	}
}

function createAjaxObj() {
	var httprequest = false;
	if (window.XMLHttpRequest) { 
		httprequest = new XMLHttpRequest();
		if (httprequest.overrideMimeType) {
			httprequest.overrideMimeType("text/xml");
		}
	} else {
		if (window.ActiveXObject) { 
			try {
				httprequest = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					httprequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
				}
			}
		}
	}
	return httprequest;
}

function getChatText() {

	
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
	
		var submitURL = "infomanage/msg/findMessage_action.jsp";
				
		receiveReq.open("POST", submitURL, true);
		
		receiveReq.onreadystatechange = handleReceiveChat; 
		receiveReq.send(null);
	}
}

function trim(str){ //删除左右两端的空格
　　     return str.replace(/(^\s*)|(\s*$)/g, "");
}

function handleReceiveChat() {
	if (receiveReq.readyState == 4) {
		var text = receiveReq.responseText;	
		if(text != "" && trim(text)!="" && text!=null){
			var curShowTime = new Date().getTime();
			if(count == 0){//第一次调用
				parent.document.getElementById("msgbox").innerHTML = text;	
				msg.show();
				lastShowTime = curShowTime;
				count++;
			}
			if(curShowTime - lastShowTime > 1000 * 30){
				count = 0;
			}
		}
		
		setTimeout("getChatText();", 1000); 
	}
}

function showDetail(id){
	var url = "infomanage/msg/message_view.jsp?itemId=" + id;
	var width = '550px';
	var height ='430px';
	var arg = "dialogHeight:" + height + ";dialogWidth:" + width + ";status:no;location:no;";
	window.showModalDialog(url, "", arg);
}
